package com.sasis.dao.ibatis;

//import java.util.Iterator;
import java.util.List;

import com.sasis.Constants;
import com.sasis.dao.DeptInfoDAO;
import com.sasis.model.DeptInfo;

/**
 * @author smith/ewen
 *
 */
public class DeptInfoDAOImpl extends BaseDaoiBATIS implements DeptInfoDAO {

	//private SqlMapClientTemplate template = this.getSqlMapClientTemplate();
	
//**insert info from form
	public int insert(DeptInfo record) {
		int id = record.getId();
		int flag = -1;
		System.out.println("..DeptInfoDAOImpl.record.getId()...."+id);
		if (id==0) {
			Object obj = getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).insert("deptInfo_insert", record);
			if (null == obj)
				flag = 1;
		} else {
			flag = getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).update("deptInfo_updateByPrimaryKey", record);
			
		}
		return flag;

	}

	public int updateByPrimaryKey(DeptInfo record) {
		int rows = getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).update("deptInfo_updateByPrimaryKey", record);

		return rows;
	}

	public List selectRef(DeptInfo record) {
		return getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).queryForList("deptInfo_selectRef", record);
	}

	public List selectAll() {
		return getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).queryForList("select_allDept", null);
	}

	public DeptInfo selectByPrimaryKey(DeptInfo key) {
		DeptInfo record = (DeptInfo) getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).queryForObject(
				"deptInfo_selectByPrimaryKey", key);

		return record;
	}

	public int deleteByPrimaryKey(DeptInfo key) {
		int rows = getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).delete("deptInfo_deleteByPrimaryKey", key);

		return rows;
	}

	public static void main(String args[]) {
		//List list=new DeptInfoDAOImpl().select(DeptInfo record);
		//Iterator it=list.iterator();
		//while(it.hasNext()){
		//  DeptInfo deptInfo=(DeptInfo)it.next();
		//  System.out.println(deptInfo.getId());

		//}
	}

	public List getRoles() {
		// TODO Auto-generated method stub
		return null;
	}

	public List getParentDepts(int deptId) {
		DeptInfo deptInfo = new DeptInfo();
		deptInfo.setId(deptId);
		List results =  getSasisSqlMapClient(Constants.FUNC_DEPT_INFO).queryForList(
				"deptInfo_getParentByPrimaryKey", deptInfo);
		
		return results;
	}
}
